import java.sql.*;

public class TestPrepStmtsSpeed {
	public static void main(String[] args) throws Exception {
		Connection connection = DriverManager.getConnection("jdbc:pointbase:server://localhost/StaplerzDB", "pbpublic", "pbpublic");
		java.util.Random generator = new java.util.Random();
		
		long tBeginSimple = System.currentTimeMillis();
		for(int i2 = 0; i2 < 1500; i2++){
			Statement statement = connection.createStatement();			
			statement.executeUpdate("UPDATE users SET name='Pablo" + generator.nextInt() + "' WHERE userid=1");
		}
		long tContSimple = System.currentTimeMillis() - tBeginSimple;
		
		long tBeginPrep = System.currentTimeMillis();
		PreparedStatement statement = connection.prepareStatement("UPDATE users SET name=? WHERE userid=?");
		for(int i1 = 0; i1 < 1500; i1++){			
			statement.setString(1, "Pablo" + generator.nextInt());
			statement.setInt(2, 1);
			statement.executeUpdate();
		}
		long tContPrep = System.currentTimeMillis() - tBeginPrep;
				
		connection.close();
		
		System.out.println(tContPrep/1000 + " sec prep");
		System.out.println(tContSimple/1000 + " sec simple");
	}
}
